//
//  SingerListTableViewController.m
//  老司机发车了
//
//  Created by SuperNing on 16/8/9.
//  Copyright © 2016年 斌. All rights reserved.
//

#import "SingerListTableViewController.h"

#import "SingerListModel.h"
#import "SingerListTableViewCell.h"
#import "DetailSongTableViewController.h"

@interface SingerListTableViewController ()

@property (nonatomic, strong)NSMutableArray *dataArray;

@end

@implementation SingerListTableViewController

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self analysedata];
    [self.tableView registerNib:[UINib nibWithNibName:@"SingerListTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    blurView.frame = self.view.bounds;

    self.tableView.backgroundView = blurView;
    
}


- (void)analysedata{
    
    NSString *detailUrl = [NSString stringWithFormat:@"%@area=%ld&sex=%ld%@",SingerDetailOne_Url,(long)_areanum,(long)_sexNum,SingerDetailTwo_Url];
    
    [NetWorkRequestManager requestWithType:POST urlString:detailUrl parDic:@{} finish:^(NSData *data) {
       
        NSDictionary *dataDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        for (NSDictionary *dict in dataDic[@"artist"]) {
            SingerListModel *model = [[SingerListModel alloc] init];
            [model setValuesForKeysWithDictionary:dict];
            [self.dataArray addObject:model];
        }
       
        dispatch_async(dispatch_get_main_queue(), ^{
           
            [self.tableView reloadData];
        });
        
    } finishError:^(NSError *error) {
        
    }];
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SingerListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    SingerListModel *model = self.dataArray[indexPath.row];
    [cell.picView sd_setImageWithURL:[NSURL URLWithString:model.avatar_big]];
    cell.nameLabel.text = model.name;
    
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 81;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DetailSongTableViewController *detailVC = [[DetailSongTableViewController alloc] init];
    SingerListModel *model = self.dataArray[indexPath.row];
    detailVC.picUrl = model.avatar_big;
    detailVC.tinguid = model.ting_uid;
    detailVC.jsonNum = 2;
    
    [self.navigationController pushViewController:detailVC animated:YES];
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
